package cn.bdqn.service;

import cn.bdqn.vo.EmailDto;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * RabbitMQ消息生产者服务
 */
@Service
public class RabbitMQProviderService {

    @Resource
    private AmqpTemplate template;

    @Value("${mq.kill.exchange}")
    private String topExchangeName;
    @Value("${mq.kill.success.email.router.key}")
    private String emailRouterKey;

    @Value("${mq.kill.dead.base.exchange}")
    private String deadBaseExchangeName;
    @Value("${mq.kill.success.dead.base.router.key}")
    private String deadBaseRouterKey;

    /**
     * 发送邮件消息的方法
     */
    public void send(EmailDto emailDto){
        //使用哪个交换机，路由键是什么，发送什么消息
        template.convertAndSend(topExchangeName,emailRouterKey,emailDto);
    }

    /**
     * 发送死信消息的方法
     */
    public void deadSend(String code){
        //使用哪个交换机，路由键是什么，发送什么消息
        template.convertAndSend(deadBaseExchangeName,deadBaseRouterKey,code);
    }

}
